// lib/models/home_swiper_image.dart
class HomeSwiperImage {
  final String id; // 数据标识，对应 _id
  final String? owner; // 所有人，系统字段
  final int createdAt; // 创建时间，毫秒时间戳
  final String? createBy; // 创建人，系统字段
  final List<String> images; // 图片数组
  final String? updateBy; // 修改人，系统字段
  final List<String>? departmentList; // 所属部门，系统字段
  final String? openid; // 记录创建者，系统字段
  final int updatedAt; // 更新时间，毫秒时间戳

  HomeSwiperImage({
    required this.id,
    this.owner,
    required this.createdAt,
    this.createBy,
    required this.images,
    this.updateBy,
    this.departmentList,
    this.openid,
    required this.updatedAt,
  });

  factory HomeSwiperImage.fromJson(Map<String, dynamic> json) {
    return HomeSwiperImage(
      id: json['_id'] as String,
      owner: json['owner'] as String?,
      createdAt: json['createdAt'] as int? ?? 0,
      createBy: json['createBy'] as String?,
      images:
          (json['images'] as List<dynamic>?)
              ?.map((item) => item as String)
              .toList() ??
          [],
      updateBy: json['updateBy'] as String?,
      departmentList:
          (json['_departmentList'] as List<dynamic>?)?.cast<String>(),
      openid: json['_openid'] as String?,
      updatedAt: json['updatedAt'] as int? ?? 0,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      '_id': id,
      'owner': owner,
      'createdAt': createdAt,
      'createBy': createBy,
      'images': images,
      'updateBy': updateBy,
      '_departmentList': departmentList,
      '_openid': openid,
      'updatedAt': updatedAt,
    };
  }
}
